package com.ease.map.common.util {
   import flash.display.InteractiveObject;
   import flash.events.Event;
   import flash.events.MouseEvent;
   import flash.events.TimerEvent;
   import flash.filters.GlowFilter;
   import flash.utils.Timer;

   public class GlowTween {
      private var _target:InteractiveObject;
      private var _color:uint;
      private var _toggle:Boolean;
      private var _blur:Number;
      private var _blurMax:Number;
      private var _blurMin:Number;
      private var _inner:Boolean;
      private var tm:Timer = null;

      public function GlowTween(target:InteractiveObject, glowNums:int = 0, color:uint = 0xFFFFFF, blurMin:Number = 2, blurMax:Number = 10, inner:Boolean = false) {
         _target = target;
         _color = color;
         _toggle = true;
         _blur = blurMin;
         _blurMin = blurMin;
         _blurMax = blurMax;
         _inner = inner;

         if(glowNums == 0){
            tm = new Timer(50);//一直闪烁
         }
         else{
            tm = new Timer(50, glowNums);
         }
         tm.addEventListener(TimerEvent.TIMER, onTimer);
         tm.addEventListener(TimerEvent.TIMER_COMPLETE,onComplete);
         tm.start();
      }

      private function onComplete(event:Event):void {
         tm = null;
         _target.filters = null;
      }

      private function onTimer(event:Event):void {
         if (_blur >= _blurMax) {
            _toggle = false;
         }
         else if (_blur <= _blurMin) {
            _toggle = true;
         }
         _toggle ? _blur++ : _blur--;
         var glow:GlowFilter = new GlowFilter(_color, 1, _blur, _blur, 2, 2, _inner);
         _target.filters = [glow];
      }
   }

}